package com.cscj.android.repository.db.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Query
import androidx.room.Upsert
import com.cscj.android.repository.db.entity.SearchHistoryEntity
import kotlinx.coroutines.flow.Flow

@Dao
interface SearchHistoryDao {

    @Query("select * from search_history order by updateTime desc limit 20")
    fun getSearchHistory(): Flow<List<SearchHistoryEntity>>

    @Upsert
    suspend fun upsertSearchHistory(searchHistoryEntity: SearchHistoryEntity)

    @Delete()
    suspend fun deleteSearchHistory(searchHistoryEntity: SearchHistoryEntity)

    @Query("delete from search_history")
    suspend fun deleteAllSearchHistory()
}